Completed
Push — master ( ee7956...a1d8a9 )
by Sand
01:08
created

sandcage.spec.js ➔ ???   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 175

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 175
rs 8.2857

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
2
'use strict';
3
4
const expect = require('chai').expect;
5
6
const specHelper = require('../lib/spec-helper');
7
const Sandcage = require('../..');
8
9
const RIGHT_KEY = specHelper.RIGHT_KEY;
10
const WRONG_KEY = specHelper.WRONG_KEY;
11
const REQUEST_ID = 'req_B8r09x8SucENLdGmHD8s08HDZDOEon';
12
const JOBS = [
13
  {
14
    "url": "http://cdn.sandcage.com/p/a/img/logo.jpg",
15
    "tasks": [
16
      {
17
        "actions": "save"
18
      },
19
      {
20
        "actions": "resize",
21
        "filename": "hello_world.jpg",
22
        "width": 200
23
      },
24
      {
25
        "actions": "crop",
26
        "coords": "10,10,50,50"
27
      },
28
      {
29
        "reference_id": "123456789",
30
        "actions": "rotate",
31
        "degrees": 90
32
      },
33
      {
34
        "actions": "cover",
35
        "width": 60,
36
        "height": 60,
37
        "cover": "middle,center"
38
      }
39
    ]
40
  },
41
  {
42
    "url": "http://cdn.sandcage.com/p/a/img/header_404.png",
43
    "tasks": [
44
      {
45
        "actions": "resize",
46
        "height": 30
47
      }
48
    ]
49
  }
50
];
51
52
const CALLBACK_URL = 'http://www.example.com/callback_url';
53
54
const FILES = [
55
  {
56
    "reference_id": "40s"
57
  },
58
  {
59
    "file_token": "file_hd869xazuhwm62f9rc6qjcj7u_v6x8akrqgpi"
60
  }
61
];
62
63
describe('Sandcage', () => {
64
65
  const sandcage = new Sandcage({apiKey: RIGHT_KEY});
66
  const sandcageWithWrongKey = new Sandcage({apiKey: WRONG_KEY});
67
68
  before('init nock', () => {
69
    specHelper.initNock();
70
  });
71
72
  describe('getInfo', () => {
73
74
    let response;
75
76
    before('call getInfo', () => {
77
      return sandcage
78
        .getInfo({'request_id': REQUEST_ID})
79
        .then((result) => {
80
          response = result;
81
        });
82
    });
83
84
    it('should contain status', () => {
85
      return expect(response.status).to.exist;
86
    });
87
88
    it('status should be "success"', () => {
89
      expect(response.status).to.be.equal('success');
90
    });
91
92
    it('files should be an array', () => {
93
      expect(response.files).to.be.an('array');
94
    });
95
  });
96
97
  describe('getInfo with wrong key', () => {
98
99
    let response;
100
101
    before('call getInfo', () => {
102
      return sandcageWithWrongKey
103
        .getInfo({'request_id': REQUEST_ID})
104
        .catch((err) => {
105
          response = err;
106
        });
107
    });
108
109
    it('should catch error', () => {
110
      return expect(response).to.exist;
111
    });
112
  });
113
114
  describe('listFiles', () => {
115
116
    let response;
117
118
    before('call listFiles', () => {
119
      return sandcage
120
        .listFiles({directory: 'img/'})
121
        .then((result) => {
122
          response = result;
123
        });
124
    });
125
126
    it('should contain status', () => {
127
      return expect(response.status).to.exist;
128
    });
129
130
    it('status should be "success"', () => {
131
      expect(response.status).to.be.equal('success');
132
    });
133
134
    it('files should be an array', () => {
135
      expect(response.files).to.be.an('array');
136
    });
137
  });
138
139
  describe('listFiles with wrong key', () => {
140
141
    let response;
142
143
    before('call listFiles', () => {
144
      return sandcageWithWrongKey
145
        .listFiles({directory: 'img/'})
146
        .catch((err) => {
147
          response = err;
148
        });
149
    });
150
151
    it('should catch error', () => {
152
      return expect(response).to.exist;
153
    });
154
  });
155
156
  describe('scheduleTasks', () => {
157
158
    let response;
159
160
    before('call scheduleTasks', () => {
161
      return sandcage
162
        .scheduleFiles({jobs: JOBS}, CALLBACK_URL)
163
        .then((result) => {
164
          response = result;
165
        });
166
    });
167
168
    it('should contain status', () => {
169
      return expect(response.status).to.exist;
170
    });
171
172
    it('status should be "success"', () => {
173
      expect(response.status).to.be.equal('success');
174
    });
175
176
    it('tasks should be an array', () => {
177
      expect(response.tasks).to.be.an('array');
178
    });
179
  });
180
181
  describe('scheduleTasks with wrong key', () => {
182
183
    let response;
184
185
    before('call scheduleTasks', () => {
186
      return sandcageWithWrongKey
187
        .scheduleFiles({jobs: JOBS}, CALLBACK_URL)
188
        .catch((err) => {
189
          response = err;
190
        });
191
    });
192
193
    it('should catch error', () => {
194
      return expect(response).to.exist;
195
    });
196
  });
197
198
  describe('destroyFiles', () => {
199
200
    let response;
201
202
    before('call destroyFiles', () => {
203
      return sandcage
204
        .destroyFiles({files: FILES}, CALLBACK_URL)
205
        .then((result) => {
206
          response = result;
207
        });
208
    });
209
210
    it('should contain status', () => {
211
      return expect(response.status).to.exist;
212
    });
213
214
    it('status should be "success"', () => {
215
      expect(response.status).to.be.equal('success');
216
    });
217
218
  });
219
220
  describe('destroyFiles with wrong key', () => {
221
222
    let response;
223
224
    before('call destroyFiles', () => {
225
      return sandcageWithWrongKey
226
        .destroyFiles({files: FILES}, CALLBACK_URL)
227
        .catch((err) => {
228
          response = err;
229
        });
230
    });
231
232
    it('should catch error', () => {
233
      return expect(response).to.exist;
234
    });
235
  });
236
237
});
238
239